package com.mqz.seckill.util;

import org.apache.commons.codec.digest.DigestUtils;

public class MD5Util {
    public static String md5(String src) {
        return DigestUtils.md5Hex(src);
    }

    //前端salt
    private static final String SALT = "4tIY5VcX";

    //第一次加盐加密
    public static String initToMidPasswd(String init) {
        String mid = SALT.charAt(0) + init + SALT.charAt(6);
        return md5(mid);
    }

    //第二次加盐加密
    public static String midToFinalPasswd(String mid, String salt) {
        String finaL = salt.charAt(1) + mid + salt.charAt(5);
        return md5(finaL);
    }

    public static String initToFinalPasswd(String init, String salt) {
        return midToFinalPasswd(initToMidPasswd(init), salt);
    }
}
